# SPDX-License-Identifier: MIT

name: Set up environment
description: .
inputs:
  python-version:
    description: The python version to install
    required: true
  cache-dependency-path:
    description: The path(s) to use for pip caching, defaults to setup + pdm
    required: false
    default: |
      pyproject.toml
      setup.py
outputs:
  python-version:
    description: The python version that was installed.
    value: ${{ steps.python-version.outputs.python-version }}

runs:
  using: composite
  steps:
    - name: Set up pdm with python ${{ inputs.python-version }}
      id: setup-python
      uses: pdm-project/setup-pdm@v3
      with:
        python-version: ${{ inputs.python-version }}
        version: "2.4.6"
        cache: false
        cache-dependency-path: ${{ inputs.cache-dependency-path }}
        enable-pep582: false  # Disable PEP 582 package loading globally
      env:
        # temporary fix, see https://github.com/pdm-project/pdm/issues/1894#issuecomment-1537126396
        PDM_DEPS: 'urllib3<2'

    - name: Disable PDM version check
      shell: bash
      run: |
        pdm config check_update false

    - name: Ignore saved pythons
      shell: bash
      run: |
        echo "PDM_IGNORE_SAVED_PYTHON=1" >> $GITHUB_ENV

    - name: Update pip, wheel, setuptools
      shell: bash
      run: python -m pip install -U pip wheel setuptools

    - name: Install nox
      shell: bash
      run: pip install nox

    - name: Set python version
      id: python-version
      shell: bash
      run: echo "python-version=$(python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')" >> $GITHUB_OUTPUT
